package com.example.chat.dao

import androidx.room.Dao
import androidx.room.MapInfo
import androidx.room.Query
import com.example.chat.model.TopicParticipant
import com.example.featuresdk.model.User
import com.example.featuresdk.dao.BasicDao
import kotlinx.coroutines.flow.Flow

@Dao
interface TopicParticipantDao: BasicDao<TopicParticipant> {

    @MapInfo(keyColumn = "topic_id")
    @Query("select tp.topic_id, u.* from topic_participant tp, user u where tp.user_id = u.id")
    fun getAll(): Flow<Map<Long, List<User>>>

    @Query("select * from user u where exists (select 1 from topic_participant where topic_id = :topicId and user_id = u.id)")
    suspend fun getOne(topicId: Long):  List<User>
}